using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

/// <summary>
/// Summary description for CheckBoxListHelper
/// </summary>
public partial class ControlHelper
{
    public void FillDataTableToCheckBoxList(
    CheckBoxList checkBoxList,
    string displayMember,
    string valueMember,
    string selectedValue)
    {

        
         
        DataTable dataTable =
        sqlServerProvider.GetDataTable();
        if (dataTable != null)
        {
            checkBoxList.DataSource = dataTable;
            checkBoxList.DataTextField = displayMember;
            checkBoxList.DataValueField = valueMember;
        }
        else
            checkBoxList.DataSource = null;
        checkBoxList.DataBind();
        if (selectedValue != "")
            checkBoxList.SelectedValue = selectedValue;
        
    }
    public void FillDataTableToCheckBoxList(
    CheckBoxList checkBoxList,
    string firstDisplayMember,
    string firstValueMember,
    string displayMember,
    string valueMember,
    string selectedValue)
    {
        
         
        DataTable dataTable =
        sqlServerProvider.GetDataTable();

        if (dataTable != null)
        {
            if (firstDisplayMember != "")
            {
                DataRow dataRow = dataTable.NewRow();
                dataRow[0] = firstDisplayMember;
                dataRow[1] = firstValueMember;
                dataTable.Rows.InsertAt(dataRow, 0);
            }
            checkBoxList.DataTextField = displayMember;
            checkBoxList.DataValueField = valueMember;
            checkBoxList.DataSource = dataTable;
            checkBoxList.DataBind();
            if (selectedValue != "")
                checkBoxList.SelectedValue = selectedValue;
        }
        else
        {
            checkBoxList.Items.Add(
            new ListItem(firstDisplayMember,
            firstValueMember));
        }

        
    }
    void FillStringToCheckBoxList(
    CheckBoxList checkBoxList,

    string firstDisplayMember,
    string firstValueMember)
    {
        if (firstDisplayMember != "")
        {
            checkBoxList.Items.Add(
            new ListItem(firstDisplayMember,
            firstValueMember));
        }
        string[] valueCollection =
        sqlServerProvider.GetStrings();
        for (int i = 0; i < valueCollection.Length; i++)
        {
            checkBoxList.Items.Add(
            valueCollection[i]);
        }

    }
    public void FillArrayListToCheckBoxList(
    CheckBoxList checkBoxList,
    string firstDisplayMember,
    string firstValueMember,
    string selectedValue)
    {

        ArrayList arrayList = sqlServerProvider.GetArrayList();
        if (arrayList.Count != 0)
        {
            FillArrayListToCheckBoxList(
            checkBoxList, arrayList,
            firstDisplayMember, firstValueMember);
            if (selectedValue != "")
                checkBoxList.SelectedValue = selectedValue;
        }

        
    }
    void FillArrayListToCheckBoxList(
    CheckBoxList checkBoxList,
    ArrayList arrayList,
    string firstDisplayMember,
    string firstValueMember)
    {
        if (firstDisplayMember != "")
        {
            checkBoxList.Items.Add(
            new ListItem(firstDisplayMember,
            firstValueMember));
        }
        for (int i = 0; i < arrayList.Count; i++)
        {
            string[] item = (string[])arrayList[i];
            checkBoxList.Items.Add(
            new ListItem(item[1], item[0]));
        }

    }
}
